Skip to content

🧱 static integration testing - #35

Merged
nstarman merged 28 commits into
data-apis:mainfrom
jorenham:type-testing
Jul 6, 2025
Merged

🧱 static integration testing#35
nstarman merged 28 commits into
data-apis:mainfrom
jorenham:type-testing

Conversation

@jorenham

@jorenham jorenham commented Jul 2, 2025

Copy link
Copy Markdown
Member

Currently limited and numpy and only uses mypy. I plan to add (based)pyright in a follow-up.

Closes ##25 I guess

@jorenham jorenham added the 🧪+ failing test Add a failing test. label Jul 2, 2025
@jorenham jorenham added this to the v2021-12-0.0 milestone Jul 2, 2025
@jorenham
jorenham requested a review from nstarman July 2, 2025 12:30
@jorenham
jorenham marked this pull request as draft July 2, 2025 12:30
@jorenham

jorenham commented Jul 2, 2025

Copy link
Copy Markdown
Member Author

So numpy isn't compatible with our HasArrayNamespace protocol, because numpy uses string literals, instead of str in the input position (which is contravariant).

@jorenham jorenham changed the title 🧱 statiic integration testing 🧱 static integration testing Jul 2, 2025

@nstarman nstarman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks great. Couple Q's.

Comment thread .github/workflows/ci.yml
Comment thread tests/integration/.ruff.toml
@nstarman

nstarman commented Jul 2, 2025

Copy link
Copy Markdown
Collaborator

What string literals does it expect? Limited to the list of compatible versions?

@jorenham

jorenham commented Jul 2, 2025

Copy link
Copy Markdown
Member Author

What string literals does it expect? Limited to the list of compatible versions?

In numpy 2.3.1 it [looks like this]:(https://github.com/numpy/numpy/blob/4d833e5df760c382f24ee3eb643dc20c3da4a5a1/numpy/__init__.pyi#L1684)

_ArrayAPIVersion: TypeAlias = L["2021.12", "2022.12", "2023.12", "2024.12"]

# --snip--

def __array_namespace__(self, /, *, api_version: _ArrayAPIVersion | None = None) -> ModuleType: ...

in 2.0.2 it looks like this:

def __array_namespace__(self, *, api_version: str | None = ...) -> Any: ...

and <2.0.0 there was no __array_namespace__

@jorenham

jorenham commented Jul 2, 2025

Copy link
Copy Markdown
Member Author

Huh, why is mypy using the stubs from numpy 2.3.1 when numpy 1.25.0 is installed?
https://github.com/data-apis/array-api-typing/actions/runs/16028175155/job/45221469410?pr=35

@jorenham

jorenham commented Jul 2, 2025

Copy link
Copy Markdown
Member Author

So mypy apparently completely ignores build isolation...

The workaround is to use uv pip install, instead of uv run --with, which layers the dependencies. It's disgustingly ugly, but at least the tests are failing for the right reasons now...

@jorenham

jorenham commented Jul 2, 2025

Copy link
Copy Markdown
Member Author

Ok, now the question remains: What to do with numpy<2? Ignore it (for now), script our way around it by using array-api-compat if numpy<2, or split it up into two separate integration tests?

@lucascolley

Copy link
Copy Markdown
Member

My feeling is that we are going to end up using array-api-compat anyway, no? I guess not for older versions of the standard, but as the standard is developed.

@jorenham

jorenham commented Jul 2, 2025

Copy link
Copy Markdown
Member Author

My feeling is that we are going to end up using array-api-compat anyway, no? I guess not for older versions of the standard, but as the standard is developed.

for the purposes of integration testing it might be a good idea to rely on it as little as we can

@jorenham

jorenham commented Jul 2, 2025

Copy link
Copy Markdown
Member Author

My feeling is that we are going to end up using array-api-compat anyway, no? I guess not for older versions of the standard, but as the standard is developed.

Testing both is also an option 🤔

@lucascolley

Copy link
Copy Markdown
Member

may as well ignore it for now if we can pass without it, and see what happens down the line

@jorenham

This comment was marked as outdated.

@jorenham

jorenham commented Jul 2, 2025

Copy link
Copy Markdown
Member Author

Nevermind, I managed to get this working on numpy<2 by using np.array_api there. It required a little bit of black voodoo magic in the gha workflow, and it's not ideal in terms of IDE support, but it's the cleanest way I could think of.

@jorenham
jorenham marked this pull request as ready for review July 2, 2025 18:23
Comment thread src/array_api_typing/_namespace.py
Comment thread .github/workflows/ci.yml
Comment thread tests/.ruff.toml

@nstarman nstarman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@jorenham jorenham added ✅ tests Add, update, or pass tests. 🏗️ architectural changes Make architectural changes. and removed 🧪+ failing test Add a failing test. labels Jul 6, 2025
@jorenham

jorenham commented Jul 6, 2025

Copy link
Copy Markdown
Member Author

@lucascolley did you want to give this another look?

@lucascolley lucascolley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks both!

it should then either fail if there's a diff

Yes, I want to figure out how to make this happen

Can we punt figuring this out for a future PR and just keep the lefthook running in addition to the separated ruff check. Cuz it'd be good to get the rest of this PR in!

Could we open an issue :)

@jorenham

jorenham commented Jul 6, 2025

Copy link
Copy Markdown
Member Author

Could we open an issue :)

#40

@nstarman
nstarman merged commit 635ea1b into data-apis:main Jul 6, 2025
@nstarman

nstarman commented Jul 6, 2025

Copy link
Copy Markdown
Collaborator

:shipit:

@jorenham
jorenham deleted the type-testing branch July 6, 2025 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏗️ architectural changes Make architectural changes. ✅ tests Add, update, or pass tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants